﻿using ComponentFactory.Krypton.Toolkit;
using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SRB.Tg.Cad
{
    public partial class SystemConfigForm : KryptonForm
    {
        string fileName = string.Empty; //图框文件名
        public SystemConfigForm()
        {
            InitializeComponent();
            cbSheet.Text = IniOper.getInstance().CurMapSheet;
            cbFont.Text = IniOper.getInstance().Font;
            FontWidth.Text = IniOper.getInstance().FontWidth;
            txtBottom.Text = IniOper.getInstance().BottomHeight;
            txtLeft.Text = IniOper.getInstance().LeftWidth;
            txtTop.Text = IniOper.getInstance().TopHeight;
            txtRight.Text = IniOper.getInstance().RightWidth;
            txtScale.Text = IniOper.getInstance().ScaleList;
            tkPath.Text = IniOper.getInstance().CurTKPath;
            modelUnit.Text = IniOper.getInstance().ModelUnit;
            layoutUnit.Text = IniOper.getInstance().LayoutUnit;
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = "dwg";
            dlg.Filter = "dwg Files|*.dwg";
            if (dlg.ShowDialog() == DialogResult.OK)
                fileName = dlg.FileName;
            if (fileName == null)
                return;
            tkPath.Text = fileName;
        }

        private void btnConfim_Click(object sender, EventArgs e)
        {

            if (!string.IsNullOrWhiteSpace(cbSheet.Text))
            {
                Extensions.curMapSheet = cbSheet.Text;
                IniOper.getInstance().CurMapSheet = cbSheet.Text;
            }
            if (!string.IsNullOrWhiteSpace(cbFont.Text))
            {
                Extensions.Font = cbFont.Text;
                IniOper.getInstance().Font = cbFont.Text;
            }
            if (!string.IsNullOrWhiteSpace(FontWidth.Text))
            {
                double fontWidth = 0.7;
                double.TryParse(FontWidth.Text, out fontWidth);
                Extensions.FontWidth = fontWidth;
                IniOper.getInstance().FontWidth = FontWidth.Text;
            }
            if (!string.IsNullOrWhiteSpace(txtBottom.Text))
            {
                double height = 30;
                double.TryParse(txtBottom.Text, out height);
                Extensions.bottomHeight = height;
                IniOper.getInstance().BottomHeight = txtBottom.Text;
            }
            if (!string.IsNullOrWhiteSpace(txtTop.Text))
            {
                double width = 15;
                double.TryParse(txtTop.Text, out width);
                Extensions.topHeight = width;
                IniOper.getInstance().TopHeight = txtTop.Text;
            }
            if (!string.IsNullOrWhiteSpace(txtLeft.Text))
            {
                double width = 15;
                double.TryParse(txtLeft.Text, out width);
                Extensions.leftWidth = width;
                IniOper.getInstance().LeftWidth = txtLeft.Text;
            }
            if (!string.IsNullOrWhiteSpace(txtRight.Text))
            {
                double width = 15;
                double.TryParse(txtRight.Text, out width);
                Extensions.rightWidth = width;
                IniOper.getInstance().RightWidth = txtRight.Text;
            }
            if (!string.IsNullOrWhiteSpace(txtScale.Text))
            {
                Extensions.scaleList = txtScale.Text;
                IniOper.getInstance().ScaleList = txtScale.Text;
            }
            if (!string.IsNullOrWhiteSpace(modelUnit.Text))
            {
                Extensions.modelunit = modelUnit.Text;
                IniOper.getInstance().ModelUnit = modelUnit.Text;
            }
            if (!string.IsNullOrWhiteSpace(layoutUnit.Text))
            {
                Extensions.layoutunit = layoutUnit.Text;
                IniOper.getInstance().LayoutUnit = layoutUnit.Text;
            }
            Extensions.curTKPath = fileName;
            
            IniOper.getInstance().CurTKPath = fileName;
            IniOper.getInstance().SaveConifg();
            InitConfig.InitStandardConfig();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
